package cn.com.zcode.core.control;

import java.util.Map;
import java.util.Set;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;


public class ApplicationInitListener implements ServletContextListener {


	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void contextInitialized(ServletContextEvent event) {
		ServletContext context = event.getServletContext();
		WebApplicationContext webcontext = WebApplicationContextUtils.getRequiredWebApplicationContext(context);
		Map<String, ApplicationInitAware> maps = webcontext .getBeansOfType(ApplicationInitAware.class);
		Set<String> sets = maps.keySet();
		for (String bename : sets) {
			ApplicationInitAware aware = maps.get(bename);
			aware.init(webcontext);
		}
	}

}
